package com.quiz.bis.service;

import com.quiz.bis.domain.model.*;
import com.quiz.bis.domain.vo.QuestionDetailVo;
import com.quiz.common.core.domain.R;
import com.quiz.common.mybatis.core.page.PageQuery;
import com.quiz.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Map;

/**
 * 错题本服务层接口
 * @author ahuan
 */
public interface IWrongQuestionService {
    // 错题本管理
    TableDataInfo<WrongQuestionBook> pageBookList(Long userId, PageQuery page);
    List<WrongQuestionBook> listBooks(Long userId);
    WrongQuestionBook getDefaultBook(Long userId);
    R<Long> createBook(WrongQuestionBook book);
    R<Void> updateBook(WrongQuestionBook book);
    R<Void> deleteBook(Long bookId);
    R<Void> setDefaultBook(Long userId, Long bookId);

    // 错题记录管理
    TableDataInfo<WrongQuestionRecord> pageRecordList(Long bookId,
                                                      Integer isMastered,
                                                      Integer typeId,
                                                      String questionText,
                                                      Integer difficulty,
                                                      PageQuery page);
    R<Void> addRecord(Long bookId, Long questionAnswerId);
    R<Void> batchAddRecords(Long bookId, List<Long> questionAnswerIds);
    R<Void> removeRecord(Long recordId);
    R<Void> batchRemoveRecords(List<Long> recordIds);
    R<Void> markMastered(Long recordId, Integer mastered);
    R<Void> updateRecordTags(Long recordId, String tagsJson);

    // 错题练习
    R<Map<String, Object>> generatePractice(Long bookId, Integer count, Integer strategy);
    R<Void> submitPractice(Long recordId, String answer, Integer timeSpent);

    // 错题统计
    TableDataInfo<WrongQuestionStats> pageStats(Long userId, Long bookId, PageQuery page);
    R<Map<String, Object>> getOverviewStats(Long userId, Long bookId);
    R<List<Map<String, Object>>> getKnowledgeStats(Long userId, Long bookId);
    R<List<Map<String, Object>>> getTypeStats(Long userId, Long bookId);

    // 智能推荐
    R<List<QuestionDetailVo>> recommendQuestions(Long recordId, Integer count, Integer strategy);


    /**
     * 获取可同步的错题列表
     * @param userId 用户ID
     * @return {@link R}<{@link List}<{@link ExamQuestionAnswers}>> 错题列表
     */
    R<List<ExamQuestionAnswers>> getWrongAnswers(Long userId);

    /**
     * 同步错题到错题本
     * @param bookId 错题本ID
     * @param answerIds 作答记录ID列表
     * @return {@link R}<{@link Void}>
     */
    R<Void> syncWrongAnswers(Long bookId, List<Long> answerIds);
}